﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Housing
{
    /// <summary>
    /// Summary description for Utils
    /// </summary>
    public class Utils
    {

        public static string GetString(object value)
        {
            if (value is DBNull || value == null)
                return "";
            else
                return value.ToString();
        }

        public static int GetNullableInt(object value)
        {
            if (value is DBNull || value == null)
                return 0;
            else
                return Convert.ToInt32(value);
        }

        public static string GetNullableDateTime(object value)
        {
            if (value is DBNull || value == null)
                return "";
            else
                return Convert.ToString(value);
        }

        public static object GetNullableValue(object value)
        {
            if (value == null || value.ToString() == "")
                return DBNull.Value;
            else
                return value;
        }

        public static float GetNullableFloat(object value)
        {
            if (value is DBNull || value == null)
                return 0;
            else
                return float.Parse(value.ToString());
        }
    }
}
